import { getStore } from '@/utils/store'
import { uploadType } from '@/utils/util'
const userInfo = getStore('userInfo') || {}
const areaLen = [userInfo.authProvince, userInfo.authCity, userInfo.authArea, userInfo.authStreetId, userInfo.authCommunityId].filter(Boolean).length

const typeDicData = [
	{
		label: '全部',
		value: 1,
		show: !userInfo.authProvince,
	},
	{
		label: '区',
		value: 2,
		show: (!userInfo.authArea && (userInfo.classifyId == 3 || userInfo.classifyId == 5)) || !userInfo.authProvince,
	},
	{
		label: '街道',
		value: 3,
		show: (!userInfo.authStreet && (userInfo.classifyId == 3 || userInfo.classifyId == 5)) || !userInfo.authProvince,
	},
	{
		label: '社区',
		value: 4,
		show: (!userInfo.authCommunity && (userInfo.classifyId == 3 || userInfo.classifyId == 5)) || !userInfo.authProvince,
	},
	{
		label: '组织',
		value: 5,
		show: areaLen <= 5 || userInfo.classifyId == 4 || !userInfo.authProvince,
	},
]
const spotAreaTypeDict = typeDicData.filter((item) => item.show)
const spotTypeDict = [
	{
		label: '数量',
		value: 1,
	},
	{
		label: '百分比',
		value: 2,
	},
]

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '规则名称',
			prop: 'ruleName',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 24,
			rules: [{ required: true, message: '请输入规则名称' }],
		},
		{
			label: '规则类型',
			prop: 'spotType',
			type: 'select',
			dicData: spotTypeDict,
			rules: [{ required: true, message: '请选择数据权限类型' }],
			span: 12,
		},
		{
			label: '规则数',
			prop: 'spotNum',
			type: 'text',
			span: 12,
			isNum: true,
			rules: [{ required: true, message: '请输入规则数' }],
		},
		{
			label: '抽查规则',
			prop: 'spotAreaType',
			type: 'radio',
			defaultValue: 1,
			dicData: spotAreaTypeDict,
			rules: [{ required: true, message: '请选择抽查规则' }],
			span: 12,
			control: (e, model) => {
				return {
					spotAreaIds: {
						display: e != 1,
					},
				}
			},
		},
		{
			label: '抽查方式',
			prop: 'spotSource',
			type: 'select',
			dicData: [
				{
					label: '服务工单',
					value: 1,
				},
				{
					label: '回访工单',
					value: 2,
				},
			],
			rules: [{ required: true, message: '请选择抽查方式' }],
			span: 12,
		},
		{
			label: '选择抽查对象',
			prop: 'spotAreaName',
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '规则名称',
			prop: 'ruleName',
			type: 'input',
			span: 8,
		},
		{
			label: '规则类型',
			prop: 'spotType',
			type: 'select',
			dicData: spotTypeDict,
			span: 8,
		},
		{
			label: '抽查规则',
			prop: 'spotAreaType',
			type: 'select',
			dicData: spotAreaTypeDict,
			span: 8,
		},
		{
			label: '创建人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '规则名称', prop: 'ruleName' },
		{
			label: '规则类型',
			prop: 'spotType',
			custome: 'tag',
			dicData: spotTypeDict,
		},
		{ label: '规则数', prop: 'spotNum' },
		{
			label: '抽查规则',
			prop: 'spotAreaType',
			custome: 'tag',
			dicData: spotAreaTypeDict,
		},
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omSpotRule_page',
	add: 'view_omSpotRule_add',
	edit: 'view_omSpotRule_edit',
	delete: 'view_omSpotRule_del',
	// detail: 'view_omSpotRule_one',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '回访抽查规则',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'ruleName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			resolve(query)
		})
	},

	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
}
